/**
 * 
 */
package evento;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import br.com.sistransporte.transite.evento.controller.EventoFacade;
import br.com.sistransporte.transitedto.evento.EventoDTO;
import br.com.src.dto.abstractdto.AbstractDTO;
import br.com.src.dto.requisicao_retorno.RequisicaoServico;
import br.com.src.dto.requisicao_retorno.RetornoServico;
import br.com.src.utilidades.Utilidades;

/**
 * Classe que representa
 *
 *
 * @author Nelson Luis da Silva Junior <nelson.jr13@hotmail.com>
 * @since 18 de Set de 2013 02:17:13
 * @version 1.0
 */
@ContextConfiguration( locations = { "classpath:rootTeste-context.xml", "classpath:rootTesteLog-context.xml" } )
@RunWith( SpringJUnit4ClassRunner.class )
public final class EventoTeste{

//	@Test
	public void filtrar() throws Throwable {
		RequisicaoServico requisicaoServico = new RequisicaoServico( "teste", new EventoDTO() );
		RetornoServico retornoServico = EventoFacade.getInstance().filtrar( requisicaoServico );

		if ( !Utilidades.isNuloOuVazio( retornoServico.erro ) ) {
			throw retornoServico.erro;
		}

		for ( AbstractDTO abstractsDTOs : retornoServico.getDtosRetorno() ) {
			System.out.println( abstractsDTOs );
		}
	}

	@Test
	public void inserir() throws Throwable{
		RequisicaoServico requisicaoServico = new RequisicaoServico( "nelson" , new EventoDTO(null, "Carnaval", "13/06/2013", "23/06/2013") );
		RetornoServico retornoServico = EventoFacade.getInstance().inserir( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	//@Test
	public void alterar() throws Throwable{
		RequisicaoServico requisicaoServico = new RequisicaoServico( "nelson" , new EventoDTO("1","FAPI", "13/06/2013", "20/06/2013"));
		RetornoServico retornoServico = EventoFacade.getInstance().alterar( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	//@Test
	public void delete() throws Throwable{
		// Consultando
		RequisicaoServico requisicaoServicoFilter = new RequisicaoServico( "teste", new EventoDTO("3") );
		RetornoServico retornoServicoFilter = EventoFacade.getInstance().filtrar( requisicaoServicoFilter );
		if ( !Utilidades.isNuloOuVazio( retornoServicoFilter.erro ) ) {
			throw retornoServicoFilter.erro;
		}
		for ( AbstractDTO abstractsDTOs : retornoServicoFilter.getDtosRetorno() ) {
			System.out.println( abstractsDTOs );
		}
		
		
		RequisicaoServico requisicaoServico = new RequisicaoServico( "gabriel" , retornoServicoFilter.getSingleDTO() );
		RetornoServico retornoServico = EventoFacade.getInstance().excluir( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	
}
